package org.mics.cyy.backUser.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import org.hibernate.annotations.Where;
import org.mics.cyy.backUser.enums.BackUserEnum;
import org.mics.jpa.entity.BaseEntity;
import org.mics.lang.security.DigestUtil;
import org.mics.lang.security.EncodeUtil;

import lombok.Data;
import lombok.EqualsAndHashCode;


/**
 * 后台用户
 * @author mics
 * @date 2020年6月9日
 * @version  1.0
 */
@Data
@Entity
@Table(name = "t_back_user")
@Where(clause = "bln_del = 0")
@EqualsAndHashCode(callSuper = false)
public class BackUserDO extends BaseEntity {
	
	 @Column(name = "nick_name", columnDefinition = "varchar(32) comment '昵称' ")
	 private String nickName; 
	 
    @Column(name = "account", unique = true, columnDefinition = "varchar(32) comment '登录账号' ")
    private String account;
    
    @Column(name = "status", columnDefinition = "tinyint(2) comment '用户状态' ")
    private BackUserEnum.Status status;

    @Column(name = "login_password", columnDefinition = "varchar(100) comment '登录密码' ")
    private String loginPassword;

    @Column(name = "login_password_salt", columnDefinition = "varchar(100) comment '登录密码盐' ")
    private String loginPasswordSalt;
    
    @Column(name = "staff_id", columnDefinition = "varchar(32) comment '员工id' ")
	 private String staffId;
    
    @Column(name = "role_id", columnDefinition = "varchar(32) comment '角色id' ")
	 private String roleId;
    
    @Column(name = "flag", columnDefinition = "varchar(32) comment '标记'")
    private String flag;

    /**
     * 构造空对象
     *
     * @return
     */
    public static BackUserDO empty() {
        BackUserDO newUser = new BackUserDO();
        //用户状态
        newUser.setStatus(BackUserEnum.Status.ACTIVE);
        //生成盐
        byte[] bytes = DigestUtil.generateSalt(5);
        String salt = EncodeUtil.encodeHex(bytes);
        newUser.setLoginPasswordSalt(salt);
        return newUser;
    }
    

}

